//
//  KLMianMiCell.m
//  KISSLOCK
//
//  Created by 华杨科技 on 2017/5/2.
//  Copyright © 2017年 陈宾鹏. All rights reserved.
//
//  免密管理界面自定义cell

#import "KLMianMiCell.h"
#import "Masonry.h"

@implementation KLMianMiCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self MakeViews];
    }
    return self;
}

- (void)MakeViews {
    [self.contentView addSubview:self.titleLb];
    [self.contentView addSubview:self.iconButton];
    
    [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(10);
        make.top.equalTo(self.contentView.mas_top);
        make.height.equalTo(self.contentView.mas_height);
    }];
    [self.iconButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLb.mas_top);
        make.left.equalTo(self.titleLb.mas_right).offset(10);
        make.right.equalTo(self.contentView.mas_right).offset(-15);
        make.height.mas_equalTo(40);
        make.width.mas_equalTo(40);
    }];
}

- (UILabel *)titleLb {
    if (!_titleLb) {
        _titleLb = [[UILabel alloc] init];
    }
    return _titleLb;
}

- (UIButton *)iconButton {
    if (!_iconButton) {
        _iconButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_iconButton setImage:[UIImage imageNamed:@"未选@2x"] forState:(UIControlStateNormal)];
        [_iconButton setImage:[UIImage imageNamed:@"选中@2x"] forState:(UIControlStateSelected)];
        
        //bug: 关掉button的交互性，不然点按钮的时候有bug，
        _iconButton.userInteractionEnabled =  NO;
    }
    return _iconButton;
}

// 切换选中状态，切换iconButton的图标
- (void)UpdateCellSelected:(BOOL)select {
    self.iconButton.selected = select;
    _isSelected = select;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
